#include "pch.h"
#include <vector>
#include <math.h>
using namespace std;
#include "RasterIO.h"
#include "MatrixSF.h"
#pragma once

class BayesD
{
public:
	BOOL Malloc_PData_Func(int iHeight);
	BOOL Malloc_PData_Func(int iHeightNum, int iWidth, int Rate);
	BOOL Free_PData_Func(int iHeight, int iWidth);

	BOOL Malloc_MeanValueMat(int iClass, int iBandNum);
	BOOL Malloc_ConMat(int iClass, int iBandNum);
	BOOL Malloc_ConMat_1(int iClass, int iBandNum);
	BOOL Malloc_XMat();
	BOOL Malloc_XMatT();

	BOOL Malloc_pLData(CString TifInPath);
	BOOL Malloc_pCData(CString ClassifyTif);

	double ** Get_Mean_Value(double ** MeanValueMat, int iRate);
	BOOL Get_Mean_Result();

	double *** Get_Covariance_Matrix1(double ** MeanValueMat, double *** ConMat);
	double *** Get_Covariance_Matrix2(double ** MeanValueMat, double *** ConMat);
	double *** Get_Covariance_Matrix3(double ** MeanValueMat, double *** ConMat);

	BOOL Bayes_Decision_Func1(double ** MeanValueMat, int iHeightNum);
	BOOL Bayes_Decision_Func2(double ** MeanValueMat, double *** ConMat_1, double * MatResult, int iHeightNum, double ** XMat, double ** XMatT);
	BOOL Bayes_Decision_Func3(double ** MeanValueMat, double *** ConMat_1, double * MatResult, int iHeightNum, double ** XMat, double ** XMatT);

	BOOL Raster_Write_Func(CString iTifPathOut);
	BOOL Get_Reverse_Matrix_of_Covariance_Matrix(double *** ConMat, double ***ConMat_1);
	BOOL Get_Determinant_Matrix_of_Covariance_Matrix(double *** ConMat, double * Result);
	BOOL WriteConFuMat(CString sPath);

	RasterIO RasterR;
	RasterIO RasterC;
	RasterIO RasterW;

	Matrix MatrixS;

	double dCount[5];
	BYTE ** pCData;
	unsigned short ** pLData;
	BOOL **pPData;

	double Rate[5];

	double ** MeanValueMat;
	double *** ConMat;
	double ** XMat;
	double ** XMatT;

	double Loss[5][5];


	double MeanResult[5];
	double MatResult[5];
	double *** ConMat_1;

	double ConfusionTestMat[5][5];
	double ConfusionTrainMat[5][5];

	double ChangeRate;
	double ChangeNum;
};